/* MyData.java 
* Created on Dec 19, 2012 
* Author:Mr.Viet
* Phone: 01683430426
* Email: phamvanvietcdhd@gmail.com
*/ 
package com.session5; 

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class MyData extends AbstractTableModel{
	private Vector<Employee> data;
	private String[] columns = {"Std Name","Address","Age"};
	public MyData(){
		this.data = new Vector<Employee>();
		this.data.addElement(new Employee("NgocNv", "HN", 30));
		this.data.addElement(new Employee("NgocNv2", "HN", 15));
		this.data.addElement(new Employee("NgocNv3", "HN", 45));
		this.data.addElement(new Employee("NgocNv4", "HN", 89));
		this.data.addElement(new Employee("NgocNv5", "HN", 34));
		
	}
	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return columns.length;
	}
	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return this.data.size();
	}
	@Override
	public Object getValueAt(int row, int column) {
		Employee e = this.data.get(row);
		switch(column){
			case 0:
				return e.getName();
			case 1:
				return e.getAddr();
			case 2:
				return e.getAge();
			
		}
		return "";
	}
	@Override
	public String getColumnName(int c) {
		return this.columns[c];
	}
	@Override
	public boolean isCellEditable(int r, int c) {
		if(c==2){//kick vao cell age
			Object value = this.getValueAt(r, c);
			int age = Integer.parseInt(value.toString());
			if(age<20) return true;
		}
		if(c==0){//student Name
			return true;
		}
		return false;
	}
}
